<template>
    <div class="body message">
        <ul class="tabNav">
            <li :class="{tab_active:iscur==0}" @click="changenav(0)">
                <div>系统消息</div>
            </li>
            <li :class="{tab_active:iscur==1}" @click="changenav(1)">
                <div>收入消息</div>
            </li>
        </ul>
        <div class="conTent" v-show="iscur==0">
            <li @click="gomsgDetial(item.id)" v-for="(item,index) in msgList" :key="index">
                <h2 v-html="item.title"></h2>
                <p v-html="item.time"></p>
                <div><span>点击查看详情 >>></span></div>
            </li>
            <div class="addmore" v-html="addmore" @click="addmorefun()"></div>
            <div style="height: 1rem;"></div>
        </div>
        <div class="conTent" v-show="iscur==1">
            <li v-for="(item,index) in msgList" :key="index">
                <h2 v-html="item.title"></h2>
                <p v-html="item.time"></p>
                <div v-html="item.content"></div>
            </li>
            <div class="addmore" v-html="addmore" @click="addmorefun()"></div>
            <div style="height: 1rem;"></div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "message",
        data(){
            return {
                iscur:0,
                addmore: "加载更多...",
                pagenomber:0,
                msgList:[]
            }
        },
        mounted(){
            this.getMessage(0);
        },
        methods:{
            changenav(statsu){
                this.iscur=statsu;
                this.getMessage(0);
            },
            gomsgDetial(msgId){
                this.$router.push({path: '/msgDetial', query: {msgId:msgId}})
            },
            //获取系统消息
            getMessage(pagenum){
                this.msgList = [];
                this.axios({
                    method: 'get',
                    url: 'apis/partner/pullMessage/'+this.iscur+'?pageNum=8&pageSize='+pagenum,
                    data: {
                        type : this.iscur,
                        pageSize:8,
                        pageNum:pagenum
                    },
                    headers: {'token':JSON.parse(localStorage.hhrdata).token},
                    withCredentials: true,
                }).then((response) => {
                    console.log(response)
                    if(response.data.code==-8){
                        this.common.checkLogin(this);
                        return
                    }
                    if(response.data.code!=0){
                        Toast({
                            message: response.data.message,
                            position: 'center',
                            duration: 2000
                        });
                    }
                    response.data.data.dataList.forEach((value,index)=> {
                        this.msgList.push({
                            time: value.creationTime,
                            content:value.content,
                            title:value.title,
                            id:value.id
                        })
                    });
                    console.log(this.msgList)

                    if(response.data.data.totalPage > pagenum+1 ){
                        this.addmore = "加载更多...";
                    }else{
                        this.addmore = "暂无更多";
                    }
                }).catch((error) => {
                    console.log(error);
                });
            },
            //加载更多分页
            addmorefun(){
                this.pagenomber++;
                if(this.addmore=="加载更多..."){
                    this.getorderList(this.pagenomber);
                }
            }
        }
    }
</script>

<style scoped lang="less">
    .message{
        background: rgba(244, 244, 244, 1);
        .conTent{
            overflow: hidden;
            background: #f4f4f4;
            padding-bottom: 1rem;
            li{
                background: #fff;
                margin: 0.2rem 0.2rem;
                h2{
                    font-size:0.3rem;
                    font-weight:700;
                    color:rgba(0,0,0,1);
                    line-height:0.5rem;
                    padding: 0.2rem 0.2rem 0 0.2rem;
                }
                p{
                    font-size:0.2rem;
                    font-weight:400;
                    color:rgba(0,0,0,1);
                    padding: 0 0.2rem;
                    line-height: 0.5rem;
                }
                div{
                    border-top: 1px dashed rgba(9,2,4,1);
                    padding: 0.2rem 0.2rem 0.3rem 0.2rem;
                    font-size:0.2rem;
                    font-weight:400;
                    color:rgba(0,0,0,0.8);
                    overflow: hidden;
                    span{
                        float: right;
                        color:rgba(38,119,249,1);
                        cursor: pointer;
                    }
                }
            }
        }
        .addmore {
            height: 0.8rem;
            text-align: center;
            line-height: 0.8rem;
            cursor: pointer;
        }
    }
</style>
